package com.projectsexception.festivales.setup.xml;

import java.io.InputStream;
import java.util.List;

import com.projectsexception.festivales.setup.FeedInfo;
import com.projectsexception.festivales.setup.MapInfo;
import com.projectsexception.festivales.setup.ShowInfo;
import com.projectsexception.festivales.util.CustomLog;

public class XMLContentReader {
    
    private static final String URL_FEEDS = "http://192.168.1.130/test/news.xml";
    private static final String URL_MAPS = "http://192.168.1.130/test/maps.xml";
    private static final String URL_SHOWS = "http://192.168.1.130/test/shows.xml";

    public List<FeedInfo> loadFeeds() {
        List<FeedInfo> feeds = null;
        FeedInfoHandler handler = new FeedInfoHandler();
        try {
            InputStream is = SAXHandlerUtil.loadInputStreamSocket(URL_FEEDS);
            if (is != null) {
                SAXHandlerUtil.launchHandler(is, handler);
                feeds = handler.getResult();
            }            
        } catch (ParseadorException e) {
            CustomLog.error("XMLContentReader", e.getMessage());
        }
        return feeds;
    }

    public List<MapInfo> loadMaps() {
        List<MapInfo> maps = null;
        MapInfoHandler handler = new MapInfoHandler();
        try {
            InputStream is = SAXHandlerUtil.loadInputStreamSocket(URL_MAPS);
            if (is != null) {
                SAXHandlerUtil.launchHandler(is, handler);
                maps = handler.getResult();
            }            
        } catch (ParseadorException e) {
            CustomLog.error("XMLContentReader", e.getMessage());
        }
        return maps;
    }

    public List<ShowInfo> loadShows() {
        List<ShowInfo> shows = null;
        ShowInfoHandler handler = new ShowInfoHandler();
        try {
            InputStream is = SAXHandlerUtil.loadInputStreamSocket(URL_SHOWS);
            if (is != null) {
                SAXHandlerUtil.launchHandler(is, handler);
                shows = handler.getResult();
            }            
        } catch (ParseadorException e) {
            CustomLog.error("XMLContentReader", e.getMessage());
        }
        return shows;
    }

}
